

package com.hdu.kdk_feign.paramHandler;

import com.hdu.kdk_feign.annotation.RequestParam;
import com.hdu.kdk_feign.utils.StringUtils;

import java.util.HashMap;


public class RequestParamParamHandler implements ParamHandler {


    @Override
    public boolean support(Param param) {
        return param.getParamAnnotation() == null
                ||
                param.getParamAnnotation().annotationType().isAssignableFrom(RequestParam.class);
    }

    @Override
    public void handle(TotalRequestParamInfo totalRequestParamInfo, Param param) {
        if (totalRequestParamInfo.getQueryParams() == null) {
            totalRequestParamInfo.setQueryParams(new HashMap<>());
        }
        RequestParam requestParam = ((RequestParam) param.getParamAnnotation());
        String paramName = StringUtils.isNotEmpty(requestParam.value()) ? requestParam.value() : param.getParamName();
        totalRequestParamInfo.getQueryParams().put(
                paramName,
                param.getParamValue()
        );
    }
}
